<template>
	<view class="main">
		<!-- #ifdef MP-WEIXIN -->
		<!-- <image class="bg" lazy-load src="@/static/img/loginBg.png" mode=""></image> -->
		<!-- #endif -->
<!-- 		<view class="logo">
			<image src="@/static/img/logo2.png" mode=""></image>
		</view> -->
		<view class="box_top">
			<!-- <view class="one">
				<view class="in">
					<view class="left">
						账号
					</view>
					<view class="right">
						<input type="text" value="" placeholder="请输入账号" v-model="data.username" />
					</view>
				</view>
			</view>
			<view class="" style="height: 4rpx;background-color: #f6f6f6;"></view> -->
				
			<view class="one">
				<view class="in">
					<view class="left">
						手机号
					</view>
					<view class="right">
						<input type="number" value="" placeholder="请输入手机号" v-model="data.mobile" />
					</view>
				</view>
			</view>
			<view class="" style="height: 4rpx;background-color: #f6f6f6;">
				
			</view>
			<view class="one">
				<view class="in">
					<view class="left">
						密码
					</view>
					<view class="right">
						<input v-model="data.password" type="password" value="" placeholder="请输入密码" />
					</view>
				</view>
			</view>
			<view class="" style="height: 4rpx;background-color: #f6f6f6;">
				
			</view>
			<!-- <view class="one">
				<view class="in code">
					<view class="left">
						验证码
					</view>
					<view class="right">
						<input v-model="data.code" type="text" value="" placeholder="请输入验证码" />
						<view @tap="getCode" class="codeBtn" v-if="!codeShow">
							获取验证码
						</view>
						<view class="codeBtn" v-else>
							<u-count-down :time="60 * 1000" format="ss" @finish="finish"></u-count-down>
							获取验证码
						</view>
					</view>
				</view>
			</view> -->
			<view class="" style="height: 4rpx;background-color: #f6f6f6;">
				
			</view>
			<view class="one">
				<view class="in">
					<view class="left" style="width: 45%;">
						邀请码
					</view>
					<view class="right">
						<input v-model="data.invate_code" type="text" value="" placeholder="请输入邀请码" />
					</view>
				</view>
			</view>
			<view class="" style="height: 4rpx;background-color: #f6f6f6;">
				
			</view>
			<view class="bottom_style">
				<view class="cottom_yinsi">
					<radio style="transform:scale(0.7)" color="#EA504F" @click="current = !current" :checked="current"/>
					<text>我已阅读、理解并同意</text> <text @click="routerTo('/pageB/text?name=Agreement&title=用户协议')">《用户协议》</text><text @click="routerTo('/pageB/text?name=Privacy&title=隐私政策')">《隐私协议》</text>
				</view>
				<view class="btn" @tap="confirm">
					确认注册
				</view>
				<view class="fn">
					<view class="left">
						已有账号？<text @tap="routerTo('/pages/login/login')">去登陆</text>
					</view>
					<view class="right" @tap="routerTo('/pageB/wpsd')">
						忘记密码？
					</view>
				</view>
			</view>

		</view>

	</view>
</template>

<script>
	import {
		register,
		send
	} from '@/api/index.js'
	export default {
		data() {
			return {
				data: {
					username: '',
					mobile: '',
					password: '',
					code: '1111',
					invate_code: '',
					current: false
				},
				codeShow: false
			}
		},
		onLoad(e) {
			// console.log(e, 'e')
			if (e.scene) {
				this.data.invate_code = e.scene
			}
		},
		methods: {
			finish() {
				this.codeShow = true
				this.$forceUpdate()
			},
			async getCode() {
				if (!this.current) {
					uni.showToast({
						title: '请选中用户协议和隐私协议',
						icon: 'none'
					})
					return
				}
				if (this.data.mobile.length == 0) {
					uni.showToast({
						title: '请输入手机号',
						icon: "none"
					})
					return
				}
				let res = await send({
					mobile: this.data.mobile,
					event: 'register'
				})
				if (res.code == 1) {
					uni.showToast({
						title: '发送成功',
						icon: "none"
					})
					this.codeShow = true
				} else {
					uni.showToast({
						title: res.msg,
						icon: "none"
					})
				}
			},
			async confirm() {
				let res = await register(this.data)
				if (res.code == 1) {
					uni.showToast({
						title: '注册成功',
						icon: 'none'
					})
					setTimeout(() => {
						uni.reLaunch({
							url: '/pages/login/login'
						})
					}, 1000)
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
				}
			},
			routerTo(url) {
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		padding: 20rpx;
		box-sizing: border-box;
		background-color: #f6f6f6;
		min-height: 100vh;
		// background-image: url(@/static/img/loginBg.png);
		background-size: 100% 100%;
		background-repeat: no-repeat;
		background-position: top left;

		::v-deep.uni-input-placeholder {
			color: #3c3c3c;
		}
	.box_top{
		
		background-color: #fff;
		height: calc(100vh - 40rpx);
		}
		.bg {
			z-index: -1;
			position: absolute;
			width: 100%;
			height: 100%;
			top: 0;
			left: 0;
		}

		.logo {
			display: flex;
			justify-content: center;
			align-items: center;
			margin-bottom: 50rpx;

			image {
				width: 310rpx;
				height: 360rpx;
			}
		}

		.msg {
			text-align: center;
			color: #3c3c3c;
			font-size: 32rpx;
			margin-bottom: 60rpx;
		}

		.one {
			padding: 0 30rpx;

			.in {
				padding: 40rpx 0;
				display: flex;
				justify-content: space-between;
				align-items: center;
				border-top: 2rpx solid #fcfcfc;

				.left {
					width: 25%;
					color: #3c3c3c;
				}

				.right {
					width: 75%;

					input {
						color: #3c3c3c;
						text-align: right;
					}
				}
			}

			.code {
				.right {
					display: flex;
					align-items: center;

					input {
						flex: 1;
					}

					.codeBtn {
						padding: 10rpx 14rpx;
						background-color: #eaeaea;
						// box-shadow: inset 0rpx 8rpx 12rpx 0rpx #07E3E3, inset 0rpx -8rpx 20rpx 0rpx #07E3E3;
						border: 2rpx solid #eaeaea;
						color: #201dd8;
						font-size: 24rpx;
						border-radius: 8rpx;
						margin-left: 6rpx;
						display: flex;
						align-items: center;
						text-indent: 4rpx;
						::v-deep.u-count-down__text {
							color: #201dd8;
							font-size: 24rpx;
							line-height: 0;
						}
					}
				}
			}
		}
		.bottom_style{
			margin: 200rpx 20rpx
		}
		.btn {
			
			width: 100%;
			padding: 30rpx;
			// box-shadow: inset 0rpx 8rpx 12rpx 0rpx #07E3E3, inset 0rpx -8rpx 20rpx 0rpx #07E3E3;
			border: 2rpx solid #ff6347;
			background-color: #ff6347;
			color: #fff;
			text-align: center;
			border-radius: 10rpx;
		}

		.fn {
			display: flex;
			justify-content: space-between;
			margin-top: 40rpx;
			.left {
				color: #9c9c9c;
				font-size: 30rpx;

				text {
						color: #ff6347;
			}
				}
			.right {
				color: #ff6347;
				font-size: 30rpx;
			}
		}
	}
	
	.cottom_yinsi {
		font-size: 20rpx;
		margin: 30rpx 0rpx 30rpx 0rpx;
		color: gray;
		display: flex;
		align-items: center;
	
		image {
			display: inline-block;
			width: 40rpx;
			height: 40rpx;
			position: relative;
			top: 11rpx;
			padding-right: 10rpx;
		}
	
		text {
			font-size: 25rpx;
			color: #666;
		}
	}
</style>